template.defaults.imports.CountdownTime = function (factEndDate) {
    var timestamp = (new Date()).valueOf();
    return factEndDate - timestamp;
};

template.defaults.imports.timestampTransfor = function (timestamp) {
    var d = new Date(timestamp); //根据时间戳生成的时间对象
    var date = (d.getFullYear()) + "-" + 
    (d.getMonth() + 1) + "-" +
    (d.getDate()) + " " + 
    (d.getHours()) + ":" + 
    (d.getMinutes()) + '' ;
    return date;
};

$(function () {
    var loading = false; //状态标记
    var hasNextPage = false;
    var pageNo = 1;
    queryList(pageNo);

    //下拉刷新
    $("#zc-list").pullToRefresh().on("pull-to-refresh", function () {
        $("#zc-content").html("");
        pageNo = 1;
        queryList(pageNo,function(){
            $("#zc-list").pullToRefreshDone(); // 重置下拉刷新
        });
    });

    //上拉加载更多
    $('#zc-list').infinite().on("infinite", function () {
        if (hasNextPage){
            pageNo++;
            queryList(pageNo,function(){
                
            },true);
        }        
    });

    function queryList(pageNo,callback,isMore){
        if (loading) return;
        loading = true;
        $.post('/antique/api/mallAuction/web/query_list', {
            start: (pageNo - 1) * 20,
            limit: 20,
            source: 1,
            showProduct:1
        }, function (result) {
            if (!isMore){
                /* global template */
                document.getElementById('zc-content').innerHTML = template('zc', result.data);                
            } else {
                $("#zc-content").append(template('zc', result.data));
            }
            hasNextPage = result.data.hasNextPage;
            if (!result.data.hasNextPage) {
                $('#loadmore').hide();
                $('#nomore').show();
            } else {
                $('#loadmore').show();
                $('#nomore').hide();
            }
            if (callback) callback();
            loading = false;
        });
    }
});